-- dark_force2
-- created by shuzy
-- 黑暗原力（道具），降低敌人攻击、生命值

return {
    apply = function(source, target, skillId, round, para, extra)
        -- 作用效果
        local valueAttack = para[1];
        local valueHp = para[2];

        -- 降低生命不允许超过90%
        valueHp = math.min(valueHp, 900);

        -- 如果是boss
        if target:isBoss() then
            valueAttack = math.modf(valueAttack / 2);
            valueHp = math.modf(valueHp / 2);
        end

        -- 血量减少
        local currHp = target:getHp("hp");
        local reduceHp = math.modf(currHp * valueHp / 1000);
        local hpV = math.modf(currHp - reduceHp);
        hpV = math.max(hpV, 1);
        target:setHp(hpV);

        -- 攻击削弱
        local currAttack = target.dbase:query("attack");

        local reduceAttack = math.modf(currAttack * valueAttack / 1000);
        local attackV = math.modf(currAttack - reduceAttack);
        attackV = math.max(attackV, 1);

        target.dbase:set("attack", attackV);

        -- 增加属性，记在怪物身上
        local propId = PropM.getPropId("attrib2");
        local prop = target.dbase:queryTemp("prop", "add_attrib_mon", {});
        if #prop > 0 then
            local value = prop[1][3];
            local reduceMon = math.modf(value * valueAttack / 1000);
            value = value - reduceMon;

            prop = { propId, "attack", value, -1, };
            target.dbase:setTemp("prop", "add_attrib_mon", { prop, });

            -- 重整一次属性
            PropM.arrangeProps(target);
        end

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), tonumber(arr[2]), tonumber(arr[3]), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        return desc;
    end,
};
